﻿
function getFlash() {
    var fo = new SWFObject("swfupload.swf", "selectFiles", "98", "38", "9.0.16.0");
    fo.addVariable("filterStr", '*.txt*;*.epub;*.ebk3;');
    fo.addVariable("uploadUrl", 'http://' + location.host);
    fo.addParam("align", "middle");
    fo.addParam("wmode", "window");
    fo.addParam("quality", "high");
    fo.addParam("allowScriptAccess", "always");
    fo.addParam("allowFullScreen", "true");
    fo.write("DocinViewer");
}

var d = document, gid = function (i) { return d.getElementById(i); };
function beginUpload() {
    var tbody = gid("cont_tab"), str = [];
    var tr = tbody.getElementsByTagName("tr");
    for (var i = 0; i < tr.length; i++) {
        str.push(tr[i].getAttribute("rel"));
    }
    str.join(",");
}
function flashStart() {
    gid("beginUpload").onclick = function () {
        gid("selectFiles").uploadStartuploadStart();
    }
}
function cancelFiles(id) {
    var num = gid(id).getAttribute("rel");
    gid("selectFiles").cancelUploadcancelUpload(num);
    gid("upload" + num).style.display = "none";
}
function selectFiles(str) {

    var tbody = gid("cont_tab"), temp = [];
    var files = str.split("|");
    temp.push("<table width='100%'><tbody>");
    for (var i = 0; i < files.length; i++) {
        temp.push('<tr rel="' + i + '" id="upload' + i + '"><td class="fileInfo">' + files[i] + '</td><td class="uploadInfo"><span id="pro' + i + '"></span><input rel=' + i + ' id="button' + i + '" type="button" onclick="cancelFiles(this.id);" value="取消" class="upfile del" /></td></tr>');
    }
    temp.push("</tbody></table>");
    tbody.innerHTML = temp.join("");
}
function uploadComplete(id) {
    var span = gid("pro" + id);
    span.innerHTML = "完成";
    span.style.backgroundPosition = "0 0";
    gid("button" + id).style.display = "none";
}
function uploadAllComplete() {
    gid("selectFiles").style.display = "block";
    gid("beginUpload").style.display = "none";
    gid("cont_tab").innerHTML = "";
}
function uploadProgress(id, pro) {
    var pro = "-" + (200 - 2 * pro) + "px";
    gid("pro" + id).style.backgroundPosition = pro + " 0";
}

window.onload = function () {
    getFlash();
    flashStart();
}